package com.design.softwaredesign.service.impl;

import com.design.softwaredesign.front.WebAdmin;
import com.design.softwaredesign.mapper.BackLoginMapper;
import com.design.softwaredesign.service.BackLoginService;
import com.design.softwaredesign.utils.security.AES;
import com.design.softwaredesign.vo.DataVo;
import com.design.softwaredesign.vo.TokenVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author :WaiterXiaoYY
 * @description: TODO
 * @data :2020/11/3 16:12
 */
@Service
public class BackLoginServiceImpl implements BackLoginService {
    @Autowired
    private BackLoginMapper backLoginMapper;
    AES aes = new AES();
    @Override
    public DataVo<TokenVo> authAdmin(String username, String password, Integer logintime) {
        DataVo<TokenVo> dataVo = new DataVo();
        dataVo.setMsg("用户信息不存在");
        dataVo.setCode(202);
        try{
            WebAdmin webAdmin = backLoginMapper.findAdmin(username, password);

            if(webAdmin != null) {
                backLoginMapper.updateLoginTime(username, logintime);
                dataVo.setCode(200);
                dataVo.setMsg("登录成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return dataVo;
        }
        return dataVo;
    }
}
